﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;


namespace UnityEngine.UnityVideoPlayer
{
    /// <summary>
    /// 显示单张图片，自动自适应
    /// </summary>
    public class ImageView : MonoBehaviour
    {
        public Image bg;

        public RawImage rawImage;

        public AspectRatioFitter arFitter;

        public Color BgColor
        {
            get => bg.color;

            set => bg.color = value;
        }
         
        public Texture Tex
        {
            get => rawImage.texture;

            set
            {
                if (rawImage.texture == value)
                    return;
                 
                rawImage.texture = value;

                if (value != null)
                {
                    rawImage.enabled = true;

                    arFitter.aspectRatio = (float)value.width / value.height;
                }
                else
                {
                    rawImage.enabled = false;
                }
            }
        }
    }
}
